/*
 * ControlPanel.java
 * 
 * Created by demory on Mar 28, 2009, 12:42:07 PM
 * 
 * Copyright 2008 David D. Emory
 * 
 * This file is part of Five Points. See <http://www.fpdev.org> for
 * additional information regarding the project.
 * 
 * Five Points is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * Five Points is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with Five Points.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.fpdev.apps.cart.gui;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.fpdev.util.gui.GUIFactory;
import org.fpdev.util.gui.MessageArea;
import org.fpdev.apps.cart.CartEvent;
import org.fpdev.apps.cart.CartEvent.Type;
import org.fpdev.apps.cart.CartEventProcessor;

/**
 *
 * @author demory
 */
/*
public class ControlPanel extends JPanel implements ChangeListener {

  private CartEventProcessor veh_;
  private JPanel controls_;
  private LineSelector lines_;

  private JCheckBox anchorsLayerCB_, linesLayerCB_, corridorsLayerCB_, gridLayerCB_;
  private JCheckBox snapToGridCB_, antialiasCB_;

  private JSplitPane splitPane_;
  private MessageArea messages_;

  public ControlPanel(CartGUI gui, CartEventProcessor veh) {
    super(new BorderLayout());
    veh_ = veh;

    // layers selector
    anchorsLayerCB_ = GUIFactory.newCheckBox("Anchors", true);
    anchorsLayerCB_.addChangeListener(this);
    linesLayerCB_ = GUIFactory.newCheckBox("Lines", true);
    linesLayerCB_.addChangeListener(this);
    corridorsLayerCB_ = GUIFactory.newCheckBox("Corridors", true);
    corridorsLayerCB_.addChangeListener(this);
    gridLayerCB_ = GUIFactory.newCheckBox("Grid");
    gridLayerCB_.addChangeListener(this);
    JPanel layersList = GUIFactory.newColumnPanel();
    layersList.add(anchorsLayerCB_);
    layersList.add(linesLayerCB_);
    layersList.add(corridorsLayerCB_);
    layersList.add(gridLayerCB_);
    JPanel layers = new TogglePanel("Layers", new JScrollPane(layersList));
    //layers.setBorder(new EmptyBorder(0, 0, 3, 0));

    // lines selector
    lines_ = new LineSelector(gui, veh_);
    JPanel lines = new TogglePanel("Lines", lines_);
    //lines.setBorder(new EmptyBorder(0, 0, 3, 0));

    // options selector
    snapToGridCB_ = GUIFactory.newCheckBox("Snap to Grid");
    snapToGridCB_.addChangeListener(this);
    antialiasCB_ = GUIFactory.newCheckBox("Antialiasing On");
    antialiasCB_.addChangeListener(this);
    JPanel optionsList = GUIFactory.newColumnPanel();
    optionsList.add(snapToGridCB_);
    optionsList.add(antialiasCB_);
    JPanel options = new TogglePanel("Options", new JScrollPane(optionsList));
  
    controls_ = GUIFactory.newColumnPanel();
    

    controls_.add(layers);
    controls_.add(Box.createVerticalStrut(4));
    controls_.add(lines);
    controls_.add(Box.createVerticalStrut(4));
    controls_.add(options);
    controls_.setBorder(new EmptyBorder(3, 3, 3, 3));

    messages_ = new MessageArea();
    JPanel msgPanel = new JPanel(new GridLayout(1, 1));//new BorderLayout());
    msgPanel.add(messages_);//, BorderLayout.CENTER);
    
    splitPane_ = new JSplitPane(JSplitPane.VERTICAL_SPLIT, controls_, msgPanel);
    
    add(splitPane_);
  }

  public void visible() {
    splitPane_.setDividerLocation(.8);
    splitPane_.setResizeWeight(1);
  }

  public LineSelector getLineSelector() {
    return lines_;
  }

  public MessageArea getMessageArea() {
    return messages_;
  }

  public boolean getShowAnchors() {
    return anchorsLayerCB_.isSelected();
  }

  public boolean getShowLines() {
    return linesLayerCB_.isSelected();
  }

  public boolean getShowCorridors() {
    return corridorsLayerCB_.isSelected();
  }
  
  public boolean getShowGrid() {
    return gridLayerCB_.isSelected();
  }
  
  public boolean getSnapToGrid() {
    return snapToGridCB_.isSelected();
  }

  public boolean getAntialiasingOn() {
    return antialiasCB_.isSelected();
  }

  public void stateChanged(ChangeEvent e) {
    if(e.getSource() == anchorsLayerCB_ || e.getSource() == linesLayerCB_ || 
       e.getSource() == corridorsLayerCB_ || e.getSource() == gridLayerCB_ ||
       e.getSource() == antialiasCB_) {
      veh_.handleEvent(new CartEvent(Type.REFRESH_CANVAS));
    }
  }

  public class TogglePanel extends JPanel implements ActionListener {

    private JComponent content_;
    private JButton top_;
    private boolean expanded_;

    public TogglePanel(String title, JComponent content) {
      super(new BorderLayout());
      content_ = content;
      expanded_ = true;
      top_ = new JButton(title);
      top_.addActionListener(this);
      add(top_, BorderLayout.NORTH);
      add(content, BorderLayout.CENTER);
      setBorder(new BevelBorder(BevelBorder.LOWERED));
    }

    public void actionPerformed(ActionEvent e) {
      if(e.getSource() == top_) {
        if(expanded_) {
          remove(content_);
          expanded_ = false;
          this.setMaximumSize(top_.getSize());
        }
        else {
          add(content_, BorderLayout.CENTER);
          expanded_ = true;
          this.setMaximumSize(ControlPanel.this.getSize());
        }

        this.revalidate();
        ControlPanel.this.repaint();// revalidate();
      }
    }
  }
}*/
